<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('图片素材选择')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <input type="hidden" id="type" name="type" value="image">
                        <li>
                            素材名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "ii/material/";

    $(function() {
        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            clickToSelect: true,
            rememberSelected: true,
            queryParams: queryParams,
            modalName: "素材",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'description',
                    title: '描述'
                },
                {
                    field: 'url',
                    title: '图片',
                    formatter: function(value, row) {
                        console.log(value)
                        return ii.imageView(value,20);
                    }

                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.type = $("#type").val();
        return search;
    }

    /* 提交 */
    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length !=1) {
            $.modal.alertWarning("请选择一条记录");
            return;
        }
        var datas=$("#bootstrap-table").bootstrapTable('getSelections');
        var id=datas[0].id;
        var name=datas[0].name;

        var index = parent.layer.getFrameIndex(window.name);
        parent.$("#materialId").val(id);
        parent.$("#materialName").val(name);
        parent.layer.close(index);
    }
</script>
</body>
</html>